package com.yaojiaxun.logisticsPlatformSystem.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yaojiaxun.logisticsPlatformSystem.entity.CompanyInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @Auther: yjx_j
 * @Date: 2019/1/18 17:14
 * @Description:
 */
@Mapper
public interface CompanyInfoMapper extends BaseMapper<CompanyInfo> {
    @Insert("insert into company_info(company_id, company_name, phone_number, address_province, address_city,address_real, corporation, introduction, property, company_built_time," +
            "create_time, update_time) values(#{companyInfo.companyId},#{companyInfo.companyName},#{companyInfo.phoneNumber},#{companyInfo.addressProvince},#{companyInfo.addressCity},"+
            "#{companyInfo.addressReal}, #{companyInfo.corporation}," +
            "#{companyInfo.introduction}, #{companyInfo.property}, #{companyInfo.companyBuiltTime}, #{companyInfo.createTime}, #{companyInfo.updateTime})")
    public void addCom(@Param("companyInfo") CompanyInfo companyInfo);

    @Select("select * from `company_info` where `company_id`=#{companyId}")
    public CompanyInfo findCompanyById(@Param("companyId") Long companyId);

    @Update("update company_info set company_name=#{companyName}, phone_number=#{phoneNumber}, address_province=#{addressProvince}, " +
            "address_city=#{addressCity}, address_real=#{addressReal}, corporation=#{corporation}, introduction=#{introduction}, property=#{property}, " +
            "company_built_time=#{companyBuiltTime} where company_id=#{companyId}")
    public Integer updateComInfo(@RequestParam("companyInfo") CompanyInfo companyInfo);

    @Delete("delete from `company_info` where `company_id`=#{companyId}")
    public void deleteCompany(@RequestParam("companyId") Long companyId);

    @Select("select * from `company_info` where `company_name`=#{companyName}")
    public CompanyInfo findCompanyByName(@Param("companyName") String companyName);

    //取出后六条数据
    @Select("select * from company_info order by company_id desc limit 6")
    public List<CompanyInfo> findLast6Company();
}
